<template>
    <view class="content">
        <view class="top u-p-b-20">
            <view class="padding-lr-sm">
                <u-search placeholder="搜索内容" v-model="keyword" :show-action="false" height="70" @search="doSearch"></u-search>
            </view>
            <!-- <timeSearch @doSearch="doSearch" /> -->
        </view>
        
        <view class="box text-df" v-for="(item, index) in list" :key="index">
            <view class="text-llg text-bold">{{item.name}}</view>
            <!-- <view class="box-l">
                <view class="company">本司</view>
                <view class="n-company">非本司</view>
                <view></view>
            </view> -->
            <u-switch v-model="item.status" @change="edit(item)"></u-switch>
        </view>
        
        <view style="height: 94rpx;padding-top: 30rpx;">
            <u-loadmore :status="status" v-if="status != 'loadmore'" />
        </view>
        
        <view class="btn-footer" @click="$gTo(`/pages/house-manage/create-house`)">添加</view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                status: 'loadmore', //是否显示没有更多了
                page: 1,
                list: [],
                keyword: '',
                // startTime: '',
                // endTime: '',
            };
        },
        onShow() {
            this.list = []
            this.page = 1
            this.status = 'loadmore'
            this.getList()
        },
        onReachBottom() {
        	if(this.page == 1){return}
        	this.getList()
        },
        methods: {
            edit(item) {
                this.$ajax('inventorys/add_stores_houst', {
                    userToken: this.$getSync('userToken'),
                    name: item.name,//库区
                    status: item.status == true ? 1 : 0,
                }).then(ret => {
                	if (ret.status == 0) {
                        this.$toast('修改成功');
                        setTimeout(() => {
                            this.page = 1;
                            this.list = [];
                            this.status = 'loadmore';
                            this.getList()
                        }, 500)
                	} else {
                		this.$toast(ret.message);
                	}
                });
            },
            
            doSearch(data) {
                this.page = 1;
                this.list = [];
                this.status = 'loadmore';
                this.getList()
            },
            
            getList() {
            	if (this.status == 'nomore') return;
            	this.status = 'loading';
            	this.$ajax('index/get_stores_house', {
                    userToken: this.$getSync('userToken'),
                    page: this.page,
                    limit: 10,
                    keywords: this.keyword,
                }).then(ret => {
            		if (ret.status == 0) {
                        if (ret.data.length > 0) {
                        	this.list = this.list.concat(ret.data);
                        	this.page++;
                        	this.status = 'loadmore'
                        } else {
                        	this.status = 'nomore'
                        }
            		} else {
            			this.$toast(ret.message);
            		}
            	});
            },
        }
    };
</script>

<style lang="scss">
    
    page{
        background-color: #f5f5f5 !important;
    }
    .content{
        padding-bottom: 150rpx;
    }
    .top{
        background-color: #fff;
    }
    
    .box{
        display: flex;
        justify-content: space-between;
        align-items: center;
        background-color: #fff;
        border-radius: 15rpx;
        padding: 40rpx 25rpx;
        margin: 25rpx 25rpx 0;
    }
    .box-l{
        flex: 1;
        display: flex;
        justify-content: flex-start;
        align-items: center;
        padding: 0 10rpx;
    }
    .company{
        width: 80rpx;
        height: 32rpx;
        font-size: 22rpx;
        color: #ff3f33;
        // padding: 5rpx 20rpx;
        text-align: center;
        line-height: 32rpx;
        border: 2rpx solid #ffa37f;
        border-radius: 8rpx;
    }
    .n-company{
        width: 80rpx;
        height: 32rpx;
        font-size: 22rpx;
        color: #8392a5;
        // padding: 5rpx 10rpx;
        text-align: center;
        line-height: 32rpx;
        border: 2rpx solid #c1c8d2;
        border-radius: 8rpx;
    }
    
    
    

</style>
